/**
 * Created by ste on 2018/1/17.
 */

import React, { Component, PropTypes } from 'react';

import {
  Text,
  StyleSheet,
} from 'react-native';

const styles = StyleSheet.create({
  link: {
    color: 'blue',
  },
});

export default class Link extends Component {
  static propTypes = {
    children: PropTypes.string,
    onPress: PropTypes.func,
    pushPage: PropTypes.string,
    passPros: PropTypes.shape({}),
    navigation: PropTypes.shape({}),
  };
  static contextTypes = {
    navigator: PropTypes.object,
  };
  onPress = () => {
    const { onPress, pushPage } = this.props;
    if (onPress && onPress()) {
      alert('123');
      return;
    }
    const { navigation } = this.props;
    if (pushPage && navigation) {
      navigation.navigate(pushPage);
    }
  }
  render() {
    const { children } = this.props;
    return <Text style={styles.link} onPress={this.onPress}>{children}</Text>;
  }
}